//
//  SelectVipTableViewCell.m
//  fitnessmanage
//
//  Created by 众拳科技 on 2017/10/31.
//  Copyright © 2017年 zongquankeji. All rights reserved.
//

#import "SelectVipTableViewCell.h"

@implementation SelectVipTableViewCell

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        /**
         选择按钮
         */
        UIButton *selectBtn = [[UIButton alloc] init];
        [selectBtn setImage:@"icon_mchose_none"];
        [selectBtn setSelectedImage:@"icon_mchose"];
        [self.contentView addSubview:selectBtn];
        self.selectBtn = selectBtn;
        
        
        /**
         头像
         */
        UIImageView *headImageView = [[UIImageView alloc] init];
        headImageView.backgroundColor = CSRedColor;
        headImageView.layer.cornerRadius = 20;
        headImageView.layer.masksToBounds = YES;
        [self.contentView addSubview:headImageView];
        self.headImageView = headImageView;
        
        
        /**
         姓名
         */
        UILabel *nameLabel = [[UILabel alloc] init];
        nameLabel.font = MidFont;
        nameLabel.textColor = CSColorFromRGB(0x7a7a7a);
        [self.contentView addSubview:nameLabel];
        self.nameLabel = nameLabel;
        
        /**
         手机
         */
        UILabel *mobLabel = [[UILabel alloc] init];
        mobLabel.font = MidFont;
        mobLabel.textColor = CSColorFromRGB(0x7a7a7a);
        [self.contentView addSubview:mobLabel];
        self.mobLabel = mobLabel;
        
        [self setConstraints];
    }
    
    return self;
}

-(void)setConstraints{
    
    /**
     选择按钮
     */
    [self.selectBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.left.mas_equalTo(self.contentView).offset(10);
        
        make.centerY.mas_equalTo(self.contentView);
    }];
    
    /**
     头像
     */
    [self.headImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(self.contentView).offset(20);
        
        make.bottom.mas_equalTo(self.contentView).offset(-20);
        
        make.left.mas_equalTo(self.selectBtn.mas_right).offset(10);
        
        make.height.width.mas_equalTo(40);
    }];
    
    /**
     姓名
     */
    [self.nameLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(self.headImageView);
        
        make.left.mas_equalTo(self.headImageView.mas_right).offset(10);
    }];
    
    /**
     手机
     */
    [self.mobLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(self.nameLabel.mas_bottom).offset(10);
        
        make.left.mas_equalTo(self.headImageView.mas_right).offset(10);
    }];
}

-(void)setVenueVipModel:(VenueVipModel *)venueVipModel{
    
    
    self.mobLabel.text = [NSString stringWithFormat:@"联系电话：%@",venueVipModel.CellPhone];
        
    NSString *urlStr = [NSString stringWithFormat:@"%@%@",venueVipModel.Pic,mid_image];
    urlStr = [urlStr stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    [self.headImageView sd_setImageWithURL:[NSURL URLWithString:urlStr] placeholderImage:PlaceHold];
}

-(NSInteger)getAgeWithBirth:(NSString *)birth{
    
    NSDateFormatter *dateFomatter = [[NSDateFormatter alloc] init];
    
    dateFomatter.dateFormat = @"yyyy-MM-dd";
    
    // 截止时间data格式
    NSDate *expireDate = [dateFomatter dateFromString:birth];
    
    // 当前时间data格式
    NSDate *nowDate = [NSDate date];
    // 当前日历
    NSCalendar *calendar = [NSCalendar currentCalendar];
    // 需要对比的时间数据
    NSCalendarUnit unit = NSCalendarUnitYear | NSCalendarUnitMonth
    | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
    // 对比时间差
    NSDateComponents *dateCom = [calendar components:unit fromDate:expireDate toDate:nowDate options:0];
    
    return dateCom.year;
    
    
}

- (void)drawRect:(CGRect)rect
{
    CGContextRef context =UIGraphicsGetCurrentContext();
    
    CGContextBeginPath(context);
    
    CGContextSetLineWidth(context,1.0);//线宽度
    
    CGContextSetStrokeColorWithColor(context,LineBackGroundColor.CGColor);
    
    CGContextMoveToPoint(context,self.nameLabel.left,rect.size.height);
    
    CGContextAddLineToPoint(context,SCREEN_WIDTH,rect.size.height);
    
    CGContextStrokePath(context);
}
@end
